Cricket.Fixtures = {
				/* REQUIRED */
				Container: 'fixtures-container',
				ListView: 'fixtures-list-view',
				DetailsView: 'fixtures-details-view',
				TabId: 'fixtures',
				Data: {Success: 1, Message: ''},
				AllTeams: [],
				AllMonths: [],
				CurrentTeam: '',
				CurrentMonth: '',
				Reloaded: true,
				ParsedFeed: [],
				CurrentView: 'list',
				search: function() {
					//get the currently selected team
					var FixturesTeam = _gel('fixtures-teams-dropdown').value;
					var FixturesMonth = _gel('fixtures-months-dropdown').value;

					if(FixturesTeam !== this.CurrentTeam) {
						Cricket.Controller.Prefs.set('cricket_fixtures_team', FixturesTeam);
						Cricket.Fixtures.CurrentTeam = FixturesTeam;
					}
					
					if(FixturesMonth !== this.CurrentMonth) {
						Cricket.Controller.Prefs.set('cricket_fixtures_month', FixturesMonth);
						Cricket.Fixtures.CurrentMonth = FixturesMonth;
					}
					var Results = Cricket.Search.filter(this);
					return Results;
				},
				
				load: function() {
					//create dom
					Cricket.Fixtures.Reloaded = true;
					//prepare AllTeams
					Cricket.Fixtures.AllTeams = Cricket.Util.loadAllTeams(this.ParsedFeed);
					Cricket.Fixtures.AllMonths = Cricket.Util.loadAllMonths(this.ParsedFeed);
					
					//show if current
					if(this.TabId == Cricket.Controller.getCurrentTab()) {
						this.show();
					}
				},
				show: function() {
					Cricket.Controller.activateTab(this);
				},
				showList: function() {
					Cricket.Fixtures.CurrentView = 'list';
					Cricket.Fixtures.hideInners();
					_gel('fixtures-list-view').style.display 	= 'block';
					_gel('fixtures-list-header').style.display 	= 'block';
				},	
				drawList: function() {
					var Results = this.search();
					var ListContainer = 'fixtures-list-view';
					
					var ListView = document.createElement('ul');
					ListView.className = 'table-container';
					
					var RowCounter = 0;
							
					for(var i = 0; i < Results.length; i++ ) {
						if(0 === i) {
							//set the first date
							var DateShowing = new Date();
							DateShowing.setYear(Results[i].Dates.Start.getFullYear());
							DateShowing.setMonth(Results[i].Dates.Start.getMonth());
							DateShowing.setDate(Results[i].Dates.Start.getDate());
						}
						
						//compare dates
						var DateToDisplay = new Date();
						DateToDisplay.setTime(DateShowing.getTime());
						DateToDisplay.setYear(Results[i].Dates.Start.getFullYear());
						DateToDisplay.setMonth(Results[i].Dates.Start.getMonth());

						DateToDisplay.setDate(Results[i].Dates.Start.getDate());
						//compare
						if(0 === i || DateToDisplay.getTime() > DateShowing.getTime()) {
							//append and reate new
							DateShowing = DateToDisplay;
							if(0 !== i){
								DayListItem.appendChild(DayTable);
								ListView.appendChild(DayListItem);
								DayListItem = document.createElement('li'); 								
								//reset row counter
								RowCounter = 0;
							} else {
								var DayListItem = document.createElement('li'); 
							}
							
							//display day
							var DayLabel = document.createElement('div');
							DayLabel.className = 'small-green-header';
							DayLabel.innerHTML = Cricket.Util.findDayLabel(DateShowing.getDay()) + ' ' + DateShowing.getDate() + ' ' + Cricket.Util.findMonthLabel(DateShowing.getMonth());
							DayListItem.appendChild(DayLabel);
							var DayTable = document.createElement('table');
							DayTable.className = 'full-width-table';
							DayListItem.appendChild(DayTable);
							
							var DayTableBody = document.createElement('tbody');
							DayTable.appendChild(DayTableBody);
						} 
						
						if(i === (Results.length - 1)) {
							DayListItem.appendChild(DayTable);
							ListView.appendChild(DayListItem);
						}
						
						var ResultRow = document.createElement('tr');
						ResultRow.className = (0 == RowCounter%2) ? 'row-dark' : 'row-light';
						DayTableBody.appendChild(ResultRow);
						
						//draw
						var Cell1 = document.createElement('td');
						Cell1.className = 'cell-1';
						Cell1.innerHTML = Results[i].Teams[1].shortname;
						ResultRow.appendChild(Cell1);
						
						var Cell2 = document.createElement('td');
						Cell2.className = 'cell-2';
						Cell2.innerHTML = 'vs';
						ResultRow.appendChild(Cell2);
						
						var Cell3 = document.createElement('td');
						Cell3.className = 'cell-3';
						Cell3.innerHTML = Results[i].Teams[2].shortname;
						ResultRow.appendChild(Cell3);
						
						var Cell4 = document.createElement('td');
						Cell4.className = 'cell-last';
						//Cell4.innerHTML = Results[i].Dates.Start;
						
						var StartTimeString = Cricket.Util.findClockLabel(Results[i].Dates.Start);
						 
						Cell4.innerHTML = StartTimeString + ', ' +Results[i].Venue + ', ' + Results[i].Description;
						ResultRow.appendChild(Cell4);
						
						var SpacerRow = document.createElement('tr');
						DayTableBody.appendChild(SpacerRow);
						RowCounter++;
						
					}									
					
					_gel(this.ListView).innerHTML = '';
					_gel(this.ListView).appendChild(ListView); 
				},
				drawDetails: function(MatchIndex) {
					//hide loader
					_gel(Cricket.Fixtures.DetailsView).innerHTML = '';
					
					if(-1 !== MatchIndex) {
						var Match = Cricket.Fixtures.ParsedFeed[MatchIndex];
						if(typeof Match == 'object') {
							//draw all info about match that isn't from details feed
							var DetailsContainer = document.createElement('div');						
							DetailsContainer.id = Cricket.Fixtures.TabId+'-details-general';						
							var DetailsContainerInfo = document.createElement('span');
							if(Match.Teams) {
								DetailsContainerInfo.innerHTML = Match.Teams[1].fullname + ' vs ' + Match.Teams[2].fullname + ', ' +Match.Series + '<br />';															
							} 
							
							DetailsContainer.appendChild(DetailsContainerInfo);
						
							var ListToggle = document.createElement('a');
							ListToggle.onclick = Cricket.Util.generateShowList(Cricket.Fixtures);
							ListToggle.href = '#';
							ListToggle.innerHTML = 'view list';
							DetailsContainer.appendChild(ListToggle);						
							
							
							_gel(Cricket.Fixtures.DetailsView).appendChild(DetailsContainer);
							Cricket.Fixtures.CurrentView 						= 'details';
							_gel(Cricket.Fixtures.ListView).style.display 		= 'none';
							_gel(Cricket.Fixtures.DetailsView).style.display 	= 'block';
						} 				
					} else {
						Cricket.Messages.show('Match could not be found');
					}
				},
				hideInners: function() {
					_gel('fixtures-list-view').style.display 				= 'none';
					_gel('fixtures-list-view').style.display 				= 'none';
				},
				loadError: function() {
					Cricket.Fixtures.Data.Success = 0;
					Cricket.Fixtures.Data.Message = 'Information on Fixtures is currently unavailable';
					//show if current
					if(this.TabId == Cricket.Controller.getCurrentTab()) {
						this.show();
					} 
				}
			}